﻿@model List<ActionInfo>

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>SetAction</title>
    <script src="~/Scripts/jquery.min.js"></script>
    <link href="~/Content/tableStyle.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
            $(":radio").click(function () {
                $.post("/UserInfo/SetUsreAction",
                    { UId: $(this).attr("uId"), ActionId: $(this).attr("actionId"), Value: $(this).val() },
                    function (data) { });
            });

            $(".btnDel").click(function () {
                if ($(this).siblings(":checked").length <= 0) {
                    return false;
                }
                //前端删除显示状态
                $(this).siblings(":radio").attr("checked", false);
                //后台删除数据
                $.post("/UserInfo/DeleteUsreAction",
                    { UId: $(this).attr("uId"), ActionId: $(this).attr("actionId") },
                    function (data) { });
            });

        });
    </script>
</head>
<body>
    @{
        UserInfo user = ViewBag.User;
        List<R_UserInfo_ActionInfo> hasActions = ViewBag.HasActions;
    }
    <h3>给用户：@user.UName 设置特殊权限</h3>

    <table>
        <tr>
            <th>权限Id</th>
            <th>权限名</th>
            <th>权限地支</th>
            <th>请求方式</th>
            <th>操作</th>
        </tr>
        @foreach (var actionInfo in Model)
        {
            string strId = "rd_" + actionInfo.ID;

            <tr>
                <td>@actionInfo.ID</td>
                <td>@actionInfo.ActionName</td>
                <td>@actionInfo.Url</td>
                <td>@actionInfo.HttpMethod</td>
                <td>
                    @{
                        if (hasActions == null)
                        {

                            @:允许<input type="radio" uId="@user.ID" actionId="@actionInfo.ID" name="@strId" value="1" />
                            @:拒绝<input type="radio" uId="@user.ID" actionId="@actionInfo.ID" name="@strId" value="0" />
                            @:<input type="button" uId="@user.ID" actionId="@actionInfo.ID" class="btnDel" value="删除" />
                            continue;
                        }

                        R_UserInfo_ActionInfo rUA = hasActions.Where(r => r.ActionInfoID == actionInfo.ID).FirstOrDefault();
                        //是否设置了特殊权限
                        if (rUA == null)
                        {
                            @:允许<input type="radio" uId="@user.ID" actionId="@actionInfo.ID" name="@strId" value="1" />
                            @:拒绝<input type="radio" uId="@user.ID" actionId="@actionInfo.ID" name="@strId" value="0" />
                            @:<input type="button" uId="@user.ID" actionId="@actionInfo.ID" class="btnDel" value="删除" />
                            continue;
                        }

                        if (rUA.HasPermission == true)
                        {

                            @:允许<input type="radio" uId="@user.ID" checked="checked" actionId="@actionInfo.ID" name="@strId" value="1" />
                            @:拒绝<input type="radio" uId="@user.ID" actionId="@actionInfo.ID" name="@strId" value="0" />
                            @:<input type="button" uId="@user.ID" actionId="@actionInfo.ID" class="btnDel" value="删除" />
                        }
                        else
                        {
                            @:允许<input type="radio" uId="@user.ID" actionId="@actionInfo.ID" name="@strId" value="1" />
                            @:拒绝<input type="radio" uId="@user.ID" checked="checked" actionId="@actionInfo.ID" name="@strId" value="0" />
                            @:<input type="button" uId="@user.ID" actionId="@actionInfo.ID" class="btnDel" value="删除" />
                        }

                    }
                </td>
            </tr>
        }
    </table>

</body>
</html>
